<script type="text/html" template lay-done="layui.data.sendParams(d.params)">
  <div class="layui-form" lay-filter="form_early_buy">
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 120px">提前购买时间</label>
      <div class="layui-input-inline" style="width: 100px">
        <input type="number" class="layui-input" lay-verify="required" name="early_buy_minutes"
               value="10">
      </div>
      <div class="layui-inline layui-form-mid layui-word-aux">
        分钟
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 120px">提前购名单</label>
      <div class="layui-form-mid layui-inline">
        <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" id="uploadFile">
          <i class="layui-icon layui-icon-upload"></i>上传提前购名单
        </button>
      </div>
      <div class="layui-inline layui-form-mid layui-word-aux layui-font-green">
        <input type="hidden" name="is_uploaded" value="0">
        <div id="uploadMsg"></div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-footer">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
          <input type="button" lay-submit lay-filter="submit_early_buy" value="确认" class="layui-btn">
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.sendParams = function (obj) {
    layui.use(['upload'], function () {
      let $ = layui.$
        , form = layui.form
        , admin = layui.admin
        , upload = layui.upload

      //设定文件大小限制
      upload.render({
        elem: '#uploadFile'
        , url: 'agent-admin/products/' + obj.product_id + '/early_buy/upload'
        , headers: {
          Authorization: admin.getAccessToken('Bearer')
        }
        , accept: 'file'
        , done: function (res) {
          if (res.code == 0) {
            $('#uploadMsg').text('上传成功')
            $('input[name="is_uploaded"]').val(1)
          } else {
            layer.msg('上传失败: ' + res.msg)
          }
        }
      });
    })
  }
</script>
